package com.ezerg.token;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.ezerg.util.CodecUtil;
import com.ezerg.util.StringUtil;

public class DefaultTokenManager implements TokenManager {

	private static Map<String, String> tokenMap = new ConcurrentHashMap<String, String>();

	public String createToken(String username) {
		String token = CodecUtil.createUUID();
		tokenMap.put(token, username);
		return token;
	}

	public boolean checkToken(String token) {
		return (!StringUtil.isEmpty(token)) && (tokenMap.containsKey(token));
	}

	public void deleteToken(String token) {
		tokenMap.remove(token);
	}
}
